package com.example.springboot.mapper;

import com.example.springboot.entity.Comment;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface CommentMapper extends BaseMapper<Comment> {

    @Select("SELECT \n" +
            "            c.*,\n" +
            "            u.username,\n" +
            "            u.avatar AS userAvatar,\n" +
            "            ru.username AS replyUsername\n" +
            "        FROM comment c\n" +
            "        LEFT JOIN user u ON c.user_id = u.id\n" +
            "        LEFT JOIN user ru ON c.reply_user_id = ru.id\n" +
            "        WHERE c.fid = #{fid}\n" +
            "        ORDER BY c.time ASC")
    List<Comment> selectByFidWithUser(@Param("fid") Integer fid);
}
